<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>父子窗口传递数据</title>

        <link rel="stylesheet" type="text/css" src="https://www.layuicdn.com/layui/css/layui.css">
        <script src="https://www.layuicdn.com/layui/layui.js"></script>


        <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
    </head>
    <body>


        <input type="text" name="" id="text1" placeholder="从子窗口返回来的数据">
        <input type="button" value="点击打开" id="btn1">



    </body>
    <script>
        layui.use(['form', 'element', 'layer'], function() {
            var form = layui.form;
            var element = layui.element;
            var layer = layui.layer;
            //  var $ = layer.jquery;
            $("#btn1").click(function() {

                layer.open({
                    type: 2,
                    content: 'my-iframe.html',
                    success: function(layero, index) {
                        //成功打开窗口之后的方法
                        var body = layer.getChildFrame('body', index);
                        var iframeWin = window[layero.find('iframe')[0]['name']];
                        //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                        //console.log(body.html()); //得到iframe页的body内容
                        console.log(body);
                        body.find('input:text').filter("#memberName").val('Hi，我是从父页来的data');
                    },
                    end: function(index, layero) {
                        //无论是确认还是取消，只要层被销毁了，end都会执行，不携带任何参数。
                        /*     var body = layer.getChildFrame('body', index);
                             console.log('body===>'+body.html());
                             let data=body.find('input:text').filter("#subName").val();
                             console.log("data==> "+data); */

                        //console.log($(layero).find("iframe")[0]);
                       // let data = $(layero).find("iframe")[0].contentWindow.data;
                        //alert(data);
                       
                    }

                });
            })



           
        });
        
        
        function getSubData(data) {
            alert(data);
            $("#text1").val(data);
        }
    </script>






</html>
